package com.zikao.question.service.impl;

import com.zikao.question.entity.Text2Entity;
import com.zikao.question.service.Text2Service;
import lombok.experimental.Accessors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zikao.common.utils.PageUtils;
import com.zikao.common.utils.Query;

import com.zikao.question.dao.AnswerDao;
import com.zikao.question.entity.AnswerEntity;
import com.zikao.question.service.AnswerService;


@Service("answerService")
public class AnswerServiceImpl extends ServiceImpl<AnswerDao, AnswerEntity> implements AnswerService {
    @Autowired
    private Text2Service text2Service;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<AnswerEntity> page = this.page(
                new Query<AnswerEntity>().getPage(params),
                new QueryWrapper<AnswerEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<AnswerEntity> selectByMap(Map<String, Object> params) {
        return baseMapper.selectByMap(params);
    }

    @Override
    public void saveAnswer(AnswerEntity answer) {
        Text2Entity text = new Text2Entity();
        text.setContent(answer.getContent());
        text2Service.save(text);
        answer.setTextId(text.getId());
        baseMapper.insert(answer);
    }
}